// Copyright (c) 2023 CHANGLEI. All rights reserved.

// ignore_for_file: public_member_api_docs, unused_element

part of 'ui_decorator.dart';

/// Created by changlei on 2023/8/15.
///
/// UIConfig android only
final class UIConfig extends UIDecorator {
  /// UIConfig android only
  const UIConfig({
    this.privacyBookSymbol,
    this.isPrivacyAnimation,
    this.authuncheckway,
    this.privacyAnimationbool,
    this.isWindowBackButtonWorks,
    this.loginBtnBg,
    this.loginBtnText,
    this.loginBtnTextColor,
    this.loginBtnTextSize,
    this.loginbtnTextBold,
    this.switchTextColor,
    this.switchIsHide,
    this.isProtocolSeleted,
    this.switchText,
    this.privacyContentText,
    this.checkTipText,
    this.protocolName,
    this.protocolUrl,
    this.secondProtocolName,
    this.secondProtocolUrl,
    this.thirdProtocolName,
    this.thirdProtocolUrl,
    this.loginButtonWidth,
    this.loginButtonHight,
    this.privacyColor,
    this.privacyOtherTextColor,
    this.statusBarBgColor,
    this.statusBarTextColor,
    this.fitsSystemWindows,
    this.navColorBgColor,
    this.ouathStateTextColor,
    this.numberColor,
    this.numberSize,
    this.numberOffsetX,
    this.numFieldOffsetY,
    this.numFieldOffsetYB,
    this.numberBold,
    this.logBtnOffsetYB,
    this.logBtnOffsetY,
    this.privacyOffsetY,
    this.privacyOffsetYB,
    this.privacyMarginLeft,
    this.privacyMarginRight,
    this.privacyTextSize,
    this.clauseBaseColor,
    this.clauseColor,
    this.isGravityCenter,
    this.privacyNavTextSize,
    this.privacyNavClauseLayoutResID,
    this.privacyNavBgColor,
    this.privacyNavTextColor,
    this.checkBoxLocation,
    this.checkBoxImageWidth,
    this.checkBoxImageheight,
    this.isAutoClosAuthPage,
    this.authPageActInAuthPagein,
    this.authPageActInLastPageOut,
    this.authPageActOutAuthPageOut,
    this.authPageActOutNextPagein,
    this.contentView,
    this.authPageWindowMode,
    this.authPageWindowWith,
    this.authPageWindowHight,
    this.authPageWindowOffsetX,
    this.authPageWindowOffsetY,
    this.authPageWindowThemeId,
    this.authPageWindowBottom,
    this.logBtnMarginLeft,
    this.logBtnMarginRight,
    this.appLanguageType,
  });

  /// 适配
  factory UIConfig.adaptive(
    BuildContext context, {
    Color textColor = CupertinoColors.label,
    Color? privacyNavBgColor,
    String? privacyContentText,
    ({String name, String url})? userAgreement,
    ({String name, String url})? privacyPolicy,
    UIImage? logo,
    UIImage? background,
    String? welcomeText,
    VoidCallback? onSwitch,
    VoidCallback? onClose,
  }) {
    final mediaQueryData = MediaQueryData.fromView(View.of(context));
    final padding = mediaQueryData.padding;
    final top = padding.top;
    final left = padding.left;
    final right = padding.right;
    final size = mediaQueryData.size;
    final width = size.width;
    final orientation = mediaQueryData.orientation;
    T valueOf<T>(T portrait, T landscape) {
      return switch (orientation) {
        Orientation.portrait => portrait,
        Orientation.landscape => landscape,
      };
    }

    return UIConfig(
      privacyTextSize: 13,
      privacyOtherTextColor: textColor,
      privacyOffsetY: valueOf(516, 400) + top,
      privacyMarginLeft: 46.5 + left,
      privacyMarginRight: 46.5 + right,
      loginButtonWidth: double.infinity,
      loginButtonHight: 45,
      logBtnOffsetY: valueOf(448, 230) + top,
      loginBtnTextSize: 17,
      logBtnMarginLeft: 46.5 + left,
      logBtnMarginRight: 46.5 + right,
      fitsSystemWindows: false,
      statusBarBgColor: Colors.transparent,
      statusBarTextColor: true,
      numberSize: 34,
      numberBold: true,
      numFieldOffsetY: valueOf(268, 140) + top,
      numberColor: textColor,
      checkBoxImageWidth: 18,
      checkBoxImageheight: 18,
      protocolName: userAgreement?.name,
      protocolUrl: userAgreement?.url,
      secondProtocolName: privacyPolicy?.name,
      secondProtocolUrl: privacyPolicy?.url,
      authuncheckway: r'authuncheckway_secondauthdialog',
      privacyContentText: privacyContentText,
      privacyNavBgColor: privacyNavBgColor,
      loginBtnBg: r'selector_button_background',
      contentView: UIViewGroup(
        id: r'root',
        width: double.infinity,
        height: double.infinity,
        background: background,
        children: [
          if (logo != null)
            UIImageView(
              id: r'logo',
              left: (width - 79) / 2,
              top: valueOf(97, 10) + top,
              width: 79,
              height: 79,
              src: logo,
              fit: BoxFit.fill,
            ),
          if (welcomeText != null)
            UITextView(
              id: r'welcome',
              left: (width - 150) / 2,
              top: valueOf(188.5, 100) + top,
              width: 148,
              height: 30,
              title: welcomeText,
              titleColor: textColor,
              textAlignment: TextAlignment.center,
              titleFont: const UIFont(
                fontSize: 22,
                fontWeight: FontWeight.w500,
              ),
            ),
          if (onSwitch != null)
            UIViewGroup(
              id: r'switch',
              left: (width - 150) / 2,
              top: valueOf(300, 160) + top,
              width: 150,
              height: -2,
              padding: const EdgeInsets.all(20),
              onPressed: onSwitch,
              children: [
                UIImageView(
                  id: r'switchIcon',
                  width: 13,
                  height: 13,
                  top: 5,
                  src: switchImgOf(context),
                ),
                UITextView(
                  id: r'switchText',
                  width: 110,
                  height: -2,
                  left: 19,
                  title: r'切换手机号',
                  titleColor: textColor,
                  titleFont: const UIFont(
                    fontSize: 16,
                    fontWeight: FontWeight.w500,
                  ),
                ),
              ],
            ),
          if (onClose != null)
            UIImageView(
              id: r'close',
              left: width - right - 65,
              top: top,
              width: 65,
              height: valueOf(65, 35),
              padding: valueOf(
                const EdgeInsets.all(25),
                const EdgeInsets.symmetric(
                  horizontal: 25,
                  vertical: 10,
                ),
              ),
              fit: BoxFit.fill,
              src: closeImgOf(context),
              onPressed: onClose,
            ),
        ],
      ),
    );
  }

  /// switch
  static UIImage switchImgOf(BuildContext context) {
    return UIDecorator.loadAsset(
      context,
      Images.change,
      package: r'tverify',
    );
  }

  /// close
  static UIImage closeImgOf(BuildContext context) {
    return UIDecorator.loadAsset(
      context,
      Images.close,
      package: r'tverify',
    );
  }

  final bool? privacyBookSymbol;
  final bool? isPrivacyAnimation;
  final String? authuncheckway;
  final bool? privacyAnimationbool;
  final bool? isWindowBackButtonWorks;
  final String? loginBtnBg;
  final String? loginBtnText;
  final Color? loginBtnTextColor;
  final double? loginBtnTextSize;
  final bool? loginbtnTextBold;
  final Color? switchTextColor;
  final bool? switchIsHide;
  final bool? isProtocolSeleted;
  final String? switchText;
  final String? privacyContentText;
  final String? checkTipText;
  final String? protocolName;
  final String? protocolUrl;
  final String? secondProtocolName;
  final String? secondProtocolUrl;
  final String? thirdProtocolName;
  final String? thirdProtocolUrl;
  final double? loginButtonWidth;
  final double? loginButtonHight;
  final Color? privacyColor;
  final Color? privacyOtherTextColor;
  final Color? statusBarBgColor;
  final bool? statusBarTextColor;
  final bool? fitsSystemWindows;
  final Color? navColorBgColor;
  final Color? ouathStateTextColor;
  final Color? numberColor;
  final double? numberSize;
  final double? numberOffsetX;
  final double? numFieldOffsetY;
  final double? numFieldOffsetYB;
  final bool? numberBold;
  final double? logBtnOffsetYB;
  final double? logBtnOffsetY;
  final double? privacyOffsetY;
  final double? privacyOffsetYB;
  final double? privacyMarginLeft;
  final double? privacyMarginRight;
  final double? privacyTextSize;
  final Color? clauseBaseColor;
  final Color? clauseColor;
  final bool? isGravityCenter;
  final double? privacyNavTextSize;
  final String? privacyNavClauseLayoutResID;
  final Color? privacyNavBgColor;
  final Color? privacyNavTextColor;
  final double? checkBoxLocation;
  final double? checkBoxImageWidth;
  final double? checkBoxImageheight;
  final bool? isAutoClosAuthPage;
  final String? authPageActInAuthPagein;
  final String? authPageActInLastPageOut;
  final String? authPageActOutAuthPageOut;
  final String? authPageActOutNextPagein;
  final UIView? contentView;
  final bool? authPageWindowMode;
  final double? authPageWindowWith;
  final double? authPageWindowHight;
  final double? authPageWindowOffsetX;
  final double? authPageWindowOffsetY;
  final String? authPageWindowThemeId;
  final double? authPageWindowBottom;
  final double? logBtnMarginLeft;
  final double? logBtnMarginRight;
  final AuthLanguageType? appLanguageType;

  @override
  List<UIView> get _views {
    return [
      if (contentView != null) contentView!,
    ];
  }

  @override
  Map<String, dynamic> toMap() {
    return <String, dynamic>{
      'privacyBookSymbol': privacyBookSymbol,
      'isPrivacyAnimation': isPrivacyAnimation,
      'authuncheckway': authuncheckway,
      'privacyAnimationbool': privacyAnimationbool,
      'isWindowBackButtonWorks': isWindowBackButtonWorks,
      'loginBtnBg': loginBtnBg,
      'loginBtnText': loginBtnText,
      'loginBtnTextColor': loginBtnTextColor?.value,
      'loginBtnTextSize': loginBtnTextSize,
      'loginbtnTextBold': loginbtnTextBold,
      'switchTextColor': switchTextColor?.value,
      'switchIsHide': switchIsHide,
      'isProtocolSeleted': isProtocolSeleted,
      'switchText': switchText,
      'privacyContentText': privacyContentText,
      'checkTipText': checkTipText,
      'protocolName': protocolName,
      'protocolUrl': protocolUrl,
      'secondProtocolName': secondProtocolName,
      'secondProtocolUrl': secondProtocolUrl,
      'thirdProtocolName': thirdProtocolName,
      'thirdProtocolUrl': thirdProtocolUrl,
      'loginButtonWidth': loginButtonWidth,
      'loginButtonHight': loginButtonHight,
      'privacyColor': privacyColor?.value,
      'privacyOtherTextColor': privacyOtherTextColor?.value,
      'statusBarBgColor': statusBarBgColor?.value,
      'statusBarTextColor': statusBarTextColor,
      'fitsSystemWindows': fitsSystemWindows,
      'navColorBgColor': navColorBgColor?.value,
      'ouathStateTextColor': ouathStateTextColor?.value,
      'numberColor': numberColor?.value,
      'numberSize': numberSize,
      'numberOffsetX': numberOffsetX,
      'numFieldOffsetY': numFieldOffsetY,
      'numFieldOffsetYB': numFieldOffsetYB,
      'numberBold': numberBold,
      'logBtnOffsetYB': logBtnOffsetYB,
      'logBtnOffsetY': logBtnOffsetY,
      'privacyOffsetY': privacyOffsetY,
      'privacyOffsetYB': privacyOffsetYB,
      'privacyMarginLeft': privacyMarginLeft,
      'privacyMarginRight': privacyMarginRight,
      'privacyTextSize': privacyTextSize,
      'clauseBaseColor': clauseBaseColor?.value,
      'clauseColor': clauseColor?.value,
      'isGravityCenter': isGravityCenter,
      'privacyNavTextSize': privacyNavTextSize,
      'privacyNavClauseLayoutResID': privacyNavClauseLayoutResID,
      'privacyNavBgColor': privacyNavBgColor?.value,
      'privacyNavTextColor': privacyNavTextColor?.value,
      'checkBoxLocation': checkBoxLocation,
      'checkBoxImageWidth': checkBoxImageWidth,
      'checkBoxImageheight': checkBoxImageheight,
      'isAutoClosAuthPage': isAutoClosAuthPage,
      'authPageActInAuthPagein': authPageActInAuthPagein,
      'authPageActInLastPageOut': authPageActInLastPageOut,
      'authPageActOutAuthPageOut': authPageActOutAuthPageOut,
      'authPageActOutNextPagein': authPageActOutNextPagein,
      'contentView': contentView?.toMap(),
      'authPageWindowMode': authPageWindowMode,
      'authPageWindowWith': authPageWindowWith,
      'authPageWindowHight': authPageWindowHight,
      'authPageWindowOffsetX': authPageWindowOffsetX,
      'authPageWindowOffsetY': authPageWindowOffsetY,
      'authPageWindowThemeId': authPageWindowThemeId,
      'authPageWindowBottom': authPageWindowBottom,
      'logBtnMarginLeft': logBtnMarginLeft,
      'logBtnMarginRight': logBtnMarginRight,
      'appLanguageType': appLanguageType?.index,
    };
  }
}
